<?php
    include 'base.php';

    $username = $_POST['username'];
    $password = $_POST['password'];

    // $username = 'eeess';
    // $password = '74185296';
    // $telephont = '15942971111';

    $sql1 = "SELECT * FROM `user` WHERE `username`='$username'";

    $res1 = $conn->query($sql1);

    $row1 =  mysqli_fetch_assoc($res1);

    // echo json_encode($row1);


    if(!is_null($row1)){
        echo json_encode(Array(
            'code' => 3,
            'msg' => '手机号或用户名重复',
            'token' => ''
        ));
    }else{
        $sql = "INSERT INTO `user` (`username`, `password`) VALUES ('$username', '$password')";

        $res = $conn->query($sql);
    
        if($res){
            echo json_encode(Array(
                'code' => 0,
                'msg' => '注册成功',
                'token' => '9832ijds9h239hoejf0h9239h9eh923i320h'
            ));
        }else{
            echo json_encode(Array(
                'code' => 1,
                'msg' => '注册失败',
                'token' => ''
            ));
        }
    }



    
?>